import pymysql
#ip地址、用户名、密码、数据库名，charset='utf8'
# database=pymysql.connect("127.0.0.1","user","123456","mql",charset='utf8')
database = pymysql.connect(host="localhost", user="root", password="123456", database="mql")
mycursor=database.cursor()


#初始化指针
#前面有几个后面就有几个
# #格式：“INSERT INTO 表名 （字段1，字段2） VALUES (内容1，内容2）;"
#对user表插入数据
# sql="insert into user(id,username) values ('1','莫俏丽');"
# mycursor.execute(sql)
# database.commit()
#查询数据
# sql="select *from user"
# mycursor.execute(sql)
# myresult = mycursor.fetchall()     # fetchall() 获取所有记录
# for x in myresult:
#   print(x)
#限定条件查询
sql='select *from user where id="1" ';
mycursor.execute(sql)
myresult=mycursor.fetchall()
for x in myresult:
    print(x)